package com.kky.pp.activity.location

import android.Manifest
import com.kky.pp.common.Constant
import com.kky.pp.dot.DotLogEventName
import com.kky.pp.dot.DotLogUtil
import com.kky.pp.entity.IMTokenGetEntity
import com.kky.pp.rongyun.RongConfigUtil
import com.kky.pp.util.PermissionUtils
import com.kky.pp.view.Loading.LoadingDialog
import com.custom.base.entity.OkHttpBodyEntity
import com.custom.base.http.OkHttpFromBoy
import com.custom.base.http.OkHttpManager
import com.custom.base.http.SDOkHttpResoutCallBack
import com.custom.base.mvp.BasePresenterImpl


class RequestLocationPresenter : BasePresenterImpl<RequestLocationContract.View>(),
    RequestLocationContract.Presenter {


    override fun init() {
        mView?.apply {
            txtRequestPositionContainers.setOnClickListener {
                PermissionUtils.requestPermission(mActivity,
                    {
                        getIMToken()
//                        HttpRequest.commonNotify(403,"400")
                        DotLogUtil.setEventName(DotLogEventName.LOCATION_PERMISSION_GRANTED).setRemark("400").commit()
                    },
                    {
                        getIMToken()
//                        HttpRequest.commonNotify(403,"400")
                        DotLogUtil.setEventName(DotLogEventName.LOCATION_PERMISSION_GRANTED).setRemark("400").commit()
                    },
                    Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.ACCESS_COARSE_LOCATION
                )
            }
            imgViewRequestPositionCloses.setOnClickListener {
                getIMToken()
            }

//            HttpRequest.commonNotify(400,"")
            DotLogUtil.setEventName(DotLogEventName.NEW_REGISTER_USER_LOCATION_PERMISSION_GRANT_PAGE).commit()
        }
    }

    fun getIMToken() {
        LoadingDialog.showLoading(mActivity)
        OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
            override fun addBody(requestBody: OkHttpBodyEntity) {
                requestBody.setPost(Constant.im_token_Url)
            }
        }, object : SDOkHttpResoutCallBack<IMTokenGetEntity>() {
            override fun onSuccess(parms: IMTokenGetEntity) {
                RongConfigUtil.connectIM(parms.data.token)
                LoadingDialog.dismissLoading(mActivity)
            }

            override fun onFailure(code: Int, msg: String) {
            }
        })
    }

}